using System;
using System.Windows;
using System.Windows.Threading;
namespace MicroMsg.Common.Timer
{
	public class TimerObject
	{
		private const int STATUS_INIT = 0;
		private const int STATUS_START = 1;
		private const int STATUS_STOP = 2;
		private int mStatus;
		private int mNextFire;
		private int mFireCount;
		private TimerParams mTimerParams;
		public int FireCount
		{
			get
			{
				return this.mFireCount;
			}
		}
		public void init(TimerParams param)
		{
			this.mTimerParams = param;
		}
		private int getNowTicks()
		{
			return TimerSource.getTicks();
		}
		private void countNextFire()
		{
			if (this.mTimerParams.mFirstFire < this.mTimerParams.mInterval && this.mTimerParams.mFirstFire >= 0)
			{
				this.mNextFire = this.mTimerParams.mFirstFire + this.getNowTicks();
				return;
			}
			this.mNextFire = this.mTimerParams.mInterval + this.getNowTicks();
		}
		public void method_0()
		{
			if (this.mStatus != 1)
			{
				return;
			}
			if (this.getNowTicks() < this.mNextFire)
			{
				return;
			}
			if (this.mFireCount >= this.mTimerParams.mRepeatCount)
			{
				this.stop();
				return;
			}
			Dispatcher arg_55_0 = Deployment.get_Current().get_Dispatcher();
			Delegate arg_55_1 = new EventHandler(this.doTimerHandler);
			object[] array = new object[2];
			array[0] = this;
			arg_55_0.BeginInvoke(arg_55_1, array);
			this.mFireCount++;
			this.mNextFire = this.getNowTicks() + this.mTimerParams.mInterval;
		}
		public void doTimerHandler(object sender, EventArgs e)
		{
			TimerObject timerObject = sender as TimerObject;
			if (timerObject == null || timerObject.mTimerParams == null)
			{
				return;
			}
			if (timerObject.isStop())
			{
				return;
			}
			timerObject.mTimerParams.mEvtHandler.Invoke(timerObject, timerObject.mTimerParams.mEventArgs);
		}
		public void start()
		{
			this.countNextFire();
			this.mFireCount = 0;
			this.mStatus = 1;
		}
		public void stop()
		{
			this.mStatus = 2;
		}
		public bool isStop()
		{
			return this.mStatus == 2;
		}
	}
}
